import 'package:flutter/material.dart';
import 'package:flutter_animate/flutter_animate.dart';
import 'package:mandoby/core/app_export.dart';
import 'package:mandoby/core/utils/app_colors.dart';
import 'package:mandoby/core/widgets/app_bar/custom_app_bar.dart';
import 'package:mandoby/core/widgets/custom_bottom_bar.dart';
import 'package:mandoby/core/widgets/custom_scaffold_widget.dart';
import 'package:mandoby/features/pay/presentation/pages/pay_screen.dart';
import 'package:nb_utils/nb_utils.dart';

import '../../../../core/widgets/custom_elevated_button.dart';

class PlansScreen extends StatefulWidget {
  const PlansScreen({Key? key}) : super(key: key);

  @override
  State<PlansScreen> createState() => _PlansScreenState();
}

class _PlansScreenState extends State<PlansScreen> {

  int isSelected=-1;
  @override
  Widget build(BuildContext context) {print("object ${isSelected}");
    return CustomScaffoldWidget(
      decoration: AppDecoration.gradientWhiteAToBlueGray,
      appBar: CustomAppBar(),
      body: ListView(children: [
        20.hs,
        Center(
            child: Text(
          "من فضلك قم بأختيار الباقه التي تناسبك",
          style: CustomTextStyles.font24bBlack400,
        )),
        20.hs,
        Table(
          border: TableBorder.all(color: AppColors.lightGray),
          columnWidths: {
            0: FlexColumnWidth(25),
            1: FlexColumnWidth(10),
            2: FlexColumnWidth(17),
            3: FlexColumnWidth(10),
          },
          children: [_buildTableRowHeader(),
            buildTableRowItems(),
            buildTableRowItems(),
            buildTableRowItems(),
            buildTableRowItems(),
            buildTableRowItems(),
            buildTableRowItems(),
            buildTableRowItems(),

            _buildTableRowBottom()
          ],
        ).animate().slideX(duration: 550.ms),
        30.hs,

        Container(height: 5,
        margin: EdgeInsets.symmetric(horizontal: 70.w),
        child: Row(
          children: [
            Container(height: 5,
              margin: EdgeInsets.symmetric(horizontal: 70.w),
              decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(7),
                  color: AppColors.primary
              ),
            ),
          ],
        ),
        ),
        20.hs
        ,
        CustomElevatedButton(
          text: "التالي",
          margin: EdgeInsets.symmetric(horizontal: 150.w),
          onPressed: (){
            PayScreen().launch(context);
          },
        ),
        50.hs

      ],
      ),
      navBar: CustomBottomBar(selectedIndex: 3),
    );
  }

  TableRow buildTableRowItems() {
    return TableRow(children: [
      Row(
        children: [
          5.ws,
          Container(
            decoration:
                BoxDecoration(color: AppColors.primary, shape: BoxShape.circle),
            height: 5.h,
            width: 5.w,
          ),
          10.ws,
          Text("استخراج اثبات قيد ( ترم اول وثاني )",style: CustomTextStyles.font14black800.copyWith(fontWeight: FontWeight.w600),).expand(),
        ],
      ).paddingSymmetric(horizontal: 4.w, vertical: 5.h),
      CustomImageView(
        alignment: Alignment.center,
        imagePath: AppAssets.imgRectangle49,
        width: 35.w,
        height: 35.h,
        margin: EdgeInsets.only(top: 10.h),

      ),
      CustomImageView(
        alignment: Alignment.center,
        imagePath: AppAssets.imgRectangle49,
        width: 35.w,
        height: 35.h,
        margin: EdgeInsets.only(top: 10.h),

      ),
      CustomImageView(
        alignment: Alignment.center,
        imagePath: AppAssets.imgRectangle49,
        width: 35.w,
        height: 35.h,
        margin: EdgeInsets.only(top: 10.h),

      ),
    ]);
  }

  TableRow _buildTableRowHeader() {
    return TableRow(children: [
      Center(
          child: Text(
        "باقات مندوبي",
        style:
            CustomTextStyles.font18White800.copyWith(color: AppColors.black900),
      ).paddingSymmetric(horizontal: 4.w, vertical: 10.h)),
      Container(
        color:AppColors.gold,
        padding: EdgeInsets.symmetric(horizontal: 4.w, vertical: 10.h),
        child: Center(
          child: Text(
            "Gold",
            style: CustomTextStyles.font18White800,
            textAlign: TextAlign.center,
          ),
        ),
      ),
      Container(
        color: AppColors.primary,
        padding: EdgeInsets.symmetric(horizontal: 4.w, vertical: 10.h),
        child: Center(
          child: Text(
            "Premium",
            style: CustomTextStyles.font18White800,
            overflow: TextOverflow.ellipsis,
            textDirection: TextDirection.ltr,
            maxLines: 1,
          ),
        ),
      ),
      Container(
        color: AppColors.silver,
        padding: EdgeInsets.symmetric(horizontal: 4.w, vertical: 10.h),
        child: Center(
          child: Text(
            "Silver",
            style: CustomTextStyles.font18White800,
          ),
        ),
      ),
    ]);
  }

  TableRow _buildTableRowBottom() {
    return TableRow(children: [
      Center(
          child: Text(
        "أختر الان",
        style:
            CustomTextStyles.font18White800.copyWith(color: AppColors.black900,fontSize: 20),
      ).paddingSymmetric(horizontal: 4.w, vertical: 10.h)),
     Checkbox(
         activeColor: AppColors.primary,

         value: isSelected==0, onChanged: (v){
       setState(() {

         isSelected= isSelected==0?-1:0;

       });
     }),
      Checkbox(
        activeColor: AppColors.primary,

          value: isSelected==1, onChanged: (v){
        setState(() {
          isSelected=   isSelected==1?-1:1;
        });
      }),
      Checkbox(
          activeColor: AppColors.primary,

          value: isSelected==2, onChanged: (v){
        setState(() {
          isSelected=  isSelected==2?-1:2;
        });
      }),

    ]);
  }
}


